define(function(require,exports,module){

	//检测类
	var Auth = require('qd-auth-1.0');


	require.async('/plugins/jquery-validation-1.13.0/jquery.validate',function(){
		require.async('/plugins/jquery-validation-1.13.0/additional-methods',function(){
			$("#payAccountFor").validate({
				
				rules:{
					realName:{
			    		required: true,
			    		chnName:true
			    	},
			    	cardId:{
			    		required: true,
			    		isIdCardNo:true
			    	},
			    	
			    },
			    messages:{
			    	realName:{
			    		required: "请输入真实姓名",
			    		chnName: "真实姓名仅为中文"
			    	},
			    	cardId:{
			    		required: "请输入二代身份证号码",
			    		isIdCardNo: "身份证格式不对"
			    	},
			    	
			   },
			 	errorElement:'em',
				errorPlacement:function(error,element){
					element.parents("li").find(".msg_tip").html(error);	
			    },
			    success:function(element){				
					element.parents("li").find(".msg_tip").html('');		
				},
				submitHandler:function(form,event,validator){
					require.async('jquery.form',function(){
						require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
							$.layer({
								type: 1,
								closeBtn: [0,true],
								title: "&nbsp;",
								area: ['384px', '186px'],
								border: [1, 1, '#cecfd0'],
								page: {
									html: '<div id="tips"><div class="tipsWrap w384"><div class="tipsTxt"><span>实名认证中，请稍等</span></div></div></div>'
								},
								close: function(index){
									window.location.href = "/member/security/setting.html";
								},
								end: function(){
									window.location.reload();
								}

							});
						})
						$(form).ajaxSubmit({
							dataType:'json',
							success:function(data){

								//单点登录检测
								if(Auth.checkLogin(arguments[0]) == false) {return ;}

								require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
									if(data.result){
										$("#tips").html('<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont okIco">&#xe63d;</i><span>实名认证申请成功，等待系统审核</span></div><div class="tipsBtnBar"><a href="javascript:;" id="okBtn" class="okBtn">确定</a></div></div>')
										$("#okBtn").click(function(){
											window.location.href = "/member/security/setting.html";
										});
									}else{
										$("#tips").html('<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" id="okBtn" class="okBtn">确定</a></div></div>')
										$("#okBtn").click(function(){
											window.location.reload();
										});
									}
								})
							}
						});
					})
				}
			});

		})
	})
});